<%@page import="isquirrel.util.Utilities"%>
<%@page import="isquirrel.beans.User"%>
<%@page import="isquirrel.util.HibernateUtil"%>
<%@page import="java.util.Vector" %>
<%@page import="java.util.Set" %>
<%@page import="java.util.Iterator" %>
<%@page import="java.net.MalformedURLException" %>
<%@page import="isquirrel.UserManager"%>
<%@page import="java.util.List" %>
<%@page import="java.util.HashMap" %>
<%@page import="java.util.Collection" %>
<%@page pageEncoding="UTF-8"%>
<%@page contentType="text/html;charset=UTF-8"%>
<%@page import="isquirrel.beans.Url" %>
<%@page import="isquirrel.beans.Recommendation"%>  
<%@page import="isquirrel.recommender.StaticDynamicRecommender"%>

<%	
	HibernateUtil.beginTransaction();
	User u = UserManager.getUser((String) session.getAttribute("user"));
	//List<Recommendation> recs = StaticDynamicRecommender.getRecommendations(u,false,5, false);
	if (u.getInterests().size() < 1){
	//if (recs.size() < 1) {
		String r = request.getRequestURI().split("/")[1];
		out.print("<div style='font-size:2em; color: #8d8d8d'>Hello, " + u.getFirstName() + ".</div>" +
			      "<p style='font-size:1em; color: #bbb'>To get started, give us some of your interests.<br><br> <a style='font-weight:bold;font-size:1.4em;color:white;text-decoration:none; padding:3px; background-color:#A5C97F' href='/" +  r + "/servlet/Profiler?nextp=profile'>Add interests</a></p>");
		return;
		
	}
	HibernateUtil.commit();
%>

<script type="text/javascript">

	/* spawn three requests to fill up the page asynchronously */ 
		
	new Ajax.Request('/<%=request.getRequestURI().split("/")[1]%>/servlet/Articles',{

		parameters: {viewmore: "t" , latest: 0},
		method: "post",
		onSuccess: function(transport){
			$("articlespin").hide();
			$("rec_articles_content").update(transport.responseText);

			var batch = "";
			for (var i = 0; i < 5; ++i){
				batch += i + "-" + $("url_" + i + "page_0").readAttribute("href") + ",";
			}

			batch = batch.substring(0, batch.length - 2);
			
			new Ajax.Request('/<%=request.getRequestURI().split("/")[1]%>/servlet/GetDesc',{

					parameters: {subject: batch, type: 1},
					method: "get",
					onSuccess: function(transport){

						var arr = transport.responseText.evalJSON(true);
						for (var i = 0; i < 5; ++i){
							$("abs_" + i + "page_0").update(arr["abs_" + i + "page_0"]);
						}
					}
				
			});
			
		}
		
	});

	new Ajax.Request('/<%=request.getRequestURI().split("/")[1]%>/servlet/Music',{

		parameters: {viewmore: "t", latest: 0},
		method: "post",
		onSuccess: function(transport){

			$("musicspin").hide();
			$("rec_music_content").update(transport.responseText);
			$("rec_music_content").setStyle({display: "none" });
			$("rec_music_loaded").setStyle({display: "block"});
		}
		
	});

	new Ajax.Request('/<%=request.getRequestURI().split("/")[1]%>/servlet/Videos',{

		parameters: {viewmore: "t", latest: 0},
		method: "post",
		onSuccess: function(transport){

			$("videospin").hide();
			$("rec_videos_content").update(transport.responseText);
			$("rec_videos_content").setStyle({display: "none" });
			$("rec_videos_loaded").setStyle({display: "block"});
			
		}
		
	});

		
</script>
<div class='rec_header'><div style='background-image:url(/<%=request.getRequestURI().split("/")[1]%>/images/Wikipedia-32.png)' class='header_title'>Articles</div>
<span onClick="window.blind(this,'rec_articles')" class="show">Hide</span>
</div>
<div class="rec_container" id="rec_articles">
	<div id="rec_articles_loaded" class="contentloaded">Wikipedia articles for your reading needs.</div>
	<div id="rec_articles_content">
		
	</div>
		<img style="margin: 5px 0px 5px 0px" id="articlespin" src="/<%=request.getRequestURI().split("/")[1]%>/images/profilespinner.gif" />
</div>	
<div class='rec_header'><div style='background-image:url(/<%=request.getRequestURI().split("/")[1]%>/images/Youtube-32h.png)' class='header_title'>Videos</div>
<span onClick="window.blind(this,'rec_videos')" class="show">Show</span>
</div>
<div class="rec_container" id="rec_videos">
	<div style="display:none" id="rec_videos_loaded" class="contentloaded">Videos for killing your time.</div>
	<div id="rec_videos_content">
		<div id="rec_videos_content_changeable">
		</div>
	</div>
	<img style="margin: 5px 0px 5px 0px;" id="videospin" src="/<%=request.getRequestURI().split("/")[1]%>/images/profilespinner.gif" />
</div>	
<div class='rec_header'><div style='background-image:url(/<%=request.getRequestURI().split("/")[1]%>/images/LastFm-red-32.png)' class='header_title'>Music</div>
<span onClick="window.blind(this,'rec_music')" class="show">Show</span>
</div>
<div class="rec_container" id="rec_music">
	<div style="display:none" id="rec_music_loaded" class="contentloaded">Music you might enjoy.</div>
	<div id="rec_music_content">
		<div id="rec_music_content_changeable">
		</div>
	</div>
	<img style="margin: 5px 0px 5px 0px" id="musicspin" src="/<%=request.getRequestURI().split("/")[1]%>/images/profilespinner.gif" />
</div>	
<script type="text/javascript">
	// register youtube player in the DOM
	player.register();	
</script>
